package cn.sdormitory.controller;

import cn.sdormitory.attendance.vo.AttendanceRuleTimeSlot;
import cn.sdormitory.basedata.entity.BClass;
import cn.sdormitory.basedata.vo.*;
import cn.sdormitory.common.IdAndName;
import cn.sdormitory.common.dto.ResultMsg;
import cn.sdormitory.service.AppClassService;
import cn.sdormitory.service.AppSdStudentLeaveService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @创建人：zhouyang
 * @创建时间：2021/11/10 17:53
 * @version：V1.0
 */
@RestController
@RequestMapping("/app/Class")
@Api("APP端班级管理接口")
public class AppClassController {
    @Autowired
    private AppClassService appClassService;
    @Autowired
    private AppSdStudentLeaveService appSdStudentLeaveService;

    @GetMapping("/getIdAndNames")
    public ResultMsg getIdAndNames(){
        List<IdAndName<Long>> idAndNames = appClassService.getIdAndNames();
        return ResultMsg.BY_SUCCESS("获取成功",idAndNames);
    }

    @GetMapping("/getAppClassByDeptManager")
    public ResultMsg getAppClassByDeptManager(){
        List<BClassVo> vos = appClassService.getAppClassByDeptManager();
        return ResultMsg.BY_SUCCESS("获取成功",vos);
    }


    @ApiOperation(value = "APP端根据班主任ID查询对应班级列表")
    @GetMapping("/getClassListByTeacherId")
    public ResultMsg getClassListByTeacherId(Long loginId) {
        List<BClassVo> classList=appClassService.getAppClassListByTeaId(loginId);
        classList.forEach(classVo -> System.out.println(classVo));
        return  ResultMsg.BY_SUCCESS("获取成功",classList);
    }

    @ApiOperation(value = "APP端根据班主任ID查询周末未打卡名单")
    @GetMapping("/getWeekendNotClockInListByCId")
    public ResultMsg getWeekendNotClockInListByCId(Long classId, String checkDate) {
        List<BStudentListVo> classStudentVoList=appClassService.getWeekendNotClockInListByCId(classId, checkDate);
        return  ResultMsg.BY_SUCCESS("获取成功",classStudentVoList);
    }

    @ApiOperation(value = "APP端根据班主任ID查询晚寝未打卡名单")
    @GetMapping("/getDormitoryNotClockInListByCId")
    public ResultMsg getDormitoryNotClockInListByCId(Long classId, String checkDate) {
        List<BStudentListVo> classStudentVoList=appClassService.getDormitoryNotClockInListByCId(classId, checkDate);
        return  ResultMsg.BY_SUCCESS("获取成功",classStudentVoList);
    }

    @ApiOperation(value = "APP端根据班级名称查询对应班级学员列表")
    @GetMapping("/getClassStuListByCName")
    public ResultMsg getClassStuListByCName(String className) {
        List<BClassStudentVo> classStudentVoList=appClassService.getAppClassStuListByCName(className);
        return  ResultMsg.BY_SUCCESS("获取成功",classStudentVoList);
    }
    @ApiOperation(value = "APP端根据班级Id查询对应班级学员列表")
    @GetMapping("/getClassStuListByCId")
    public ResultMsg getClassStuListByCId(int classId) {
        List<BStudentListVo> classStudentVoList=appClassService.getStudentListByClassId(classId);
        return  ResultMsg.BY_SUCCESS("获取成功",classStudentVoList);
    }
    @ApiOperation(value = "APP端根据班级Id修改对应学生信息")
    @GetMapping("/upStudentById")
    public ResultMsg upStudentById(int studentId,String studentName,String studentPhone,String parentPhone) {
       int count=appClassService.updateStudent(studentId,studentName,studentPhone,parentPhone);
       if(count>0){
           return  ResultMsg.BY_SUCCESS("更新成功",count);
       }else {
           return ResultMsg.BY_ERROR("更新失败");
       }

    }

    @ApiOperation(value = "APP端根据班主任ID查询对应宿舍列表")
    @GetMapping("/getAppClassDorListByTeaId")
    public ResultMsg getAppClassDorListByTeaId(Long classTeacherId) {
        List<BClassDorVo> classList=appClassService.getAppClassDorListByTeaId(classTeacherId);
        return  ResultMsg.BY_SUCCESS("获取成功",classList);
    }

    @ApiOperation(value = "APP端根据班级名称+学生姓名查询对应学员列表包括当天请假信息")
    @GetMapping("/getLeaveByClaNameAndStuName")
    public ResultMsg getLeaveByClaNameAndStuName(String className,String studentName) {
        List<BClassStudentVo> classStudentVoList=appSdStudentLeaveService.getLeaveByClaNameAndStuName(className,studentName);
        return  ResultMsg.BY_SUCCESS("获取成功",classStudentVoList);
    }

    @ApiOperation(value = "APP端获取所有班级部门列表")
    @GetMapping("/getAppClassDept")
    public ResultMsg getAppClassDept() {
        List<ClassDeptVo> classDeptList=appClassService.getAppClassDept();
        return  ResultMsg.BY_SUCCESS("获取成功",classDeptList);
    }

    @ApiOperation(value = "APP端根据部门ID查询对应班级列表")
    @GetMapping("/getAppClassDeptByClaId")
    public ResultMsg getAppClassDeptByClaId(Long classDeptId) {
        List<BClassVo> classList=appClassService.getAppClassDeptByClaId(classDeptId);
        return  ResultMsg.BY_SUCCESS("获取成功",classList);
    }

    @ApiOperation(value = "APP端根据日期+部门ID查询班级列表及对应的考勤和违纪情况")
    @GetMapping("/getAppClassDeptAccDvByDeptId")
    public ResultMsg getAppClassDeptAccDvByDeptId(String accessDate,Long classDeptId,String timeSlot) {
        List<BClassDeptVo> classList=appClassService.getAppClassDeptAccDvByDeptId(accessDate,classDeptId,timeSlot);
        return  ResultMsg.BY_SUCCESS("获取成功",classList);
    }

    @ApiOperation(value = "APP端根据日期+部门ID+时间段查询班级列表及对应的卫生情况")
    @GetMapping("/getAppClassDeptHyByDeptId")
    public ResultMsg getAppClassDeptHyByDeptId(String accessDate,Long classDeptId,String timeSlot) {
        List<BClassDeptHyVo> classList=appClassService.getAppClassDeptHyByDeptId(accessDate,classDeptId,timeSlot);
        return  ResultMsg.BY_SUCCESS("获取成功",classList);
    }

    @ApiOperation(value = "APP端根据部门ID查询班级列表及对应的报修情况")
    @GetMapping("/getAppClassDeptReByDeptId")
    public ResultMsg getAppClassDeptReByDeptId(Long classDeptId) {
        List<BClassDeptReVo> classList=appClassService.getAppClassDeptReByDeptId(classDeptId);
        return  ResultMsg.BY_SUCCESS("获取成功",classList);
    }

    @ApiOperation(value = "APP端查询全部班级")
    @GetMapping("/getAllAppClassList")
    public ResultMsg getAllAppClassList() {
        List<BClassVo> classList=appClassService.getAllAppClassList();
        return  ResultMsg.BY_SUCCESS("获取成功",classList);
    }

    @ApiOperation(value = "APP端根据班级ID查询对应班级住宿学员列表")
    @GetMapping("/getClassStuListByClassId")
    public ResultMsg getClassStuListByClassId(String classId) {
        List<BClassStudentVo> classStudentVoList=appClassService.getClassStuListByClassId(classId);
        return  ResultMsg.BY_SUCCESS("获取成功",classStudentVoList);
    }

    @ApiOperation(value = "APP端根据班级ID查询对应班级全部学员列表")
    @GetMapping("/getClassStuListAllByClassId")
    public ResultMsg getClassStuListAllByClassId(String classId) {
        List<BClassStudentVo> classStudentVoList=appClassService.getClassStuListAllByClassId(classId);
        return  ResultMsg.BY_SUCCESS("获取成功",classStudentVoList);
    }

    @ApiOperation(value = "APP端根据班级ID查询对应班级寄宿学生人数")
    @GetMapping("/getBoardingStuCountByClassId")
    public ResultMsg getBoardingStuCountByClassId(String classId) {
        int count = appClassService.getBoardingStuCountByClassId(classId);
        return  ResultMsg.BY_SUCCESS("获取成功",count);
    }

    @ApiOperation(value = "APP端根据班级ID查询对应班级请假学生人数")
    @GetMapping("/getLeaveStuCountByClassId")
    public ResultMsg getLeaveStuCountByClassId(String classId) {
        int count = appClassService.getLeaveStuCountByClassId(classId);
        return  ResultMsg.BY_SUCCESS("获取成功",count);
    }

    @ApiOperation("根据班级ID查找班级信息")
    @GetMapping("/getClassInfoByClassId/{classId}")
    public ResultMsg getClassInfoByClassId(@PathVariable("classId") Long classId){
        BClass bClass = appClassService.getClassInfoByClassId(classId);
        return ResultMsg.BY_SUCCESS("获取成功",bClass);
    }

    @ApiOperation("根据班级ID查找班级信息")
    @GetMapping("/getClassRuleTimeSlots/{classId}")
    public ResultMsg getClassRuleTimeSlots(@PathVariable("classId") Long classId){
        List<AttendanceRuleTimeSlot> timeSlots = appClassService.getClassRuleTimeSlots(classId);
        return ResultMsg.BY_SUCCESS("获取成功",timeSlots);
    }

    @ApiOperation("更新班级信息")
    @PostMapping("/UpdateClassInfo")
    public ResultMsg UpdateClassInfo(@RequestBody BClass bClass){
        if(bClass.getId() == null){
            return ResultMsg.BY_SUCCESS("班级ID不允许为空");
        }
        int num = appClassService.UpdateClassInfo(bClass);
        if(num > 0){
            return ResultMsg.BY_SUCCESS("修改成功");
        }else {
            return ResultMsg.BY_FAIL("修改失败");
        }
    }
}
